package com.itzxx.huazhun.ui.record.curve

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.chad.library.adapter4.BaseQuickAdapter
import com.itzxx.huazhun.data.model.DetailedList
import com.itzxx.huazhun.databinding.ItemDevicesBinding
import com.itzxx.huazhun.data.model.DevicesBean
import com.itzxx.huazhun.data.model.DevicesChildBean
import com.itzxx.huazhun.databinding.ItemCurveDataListBinding

/**
 * Desc:
 *
 * Author: zhangxiaoxiao
 * Date: 2024/7/4 10:42
 * Updater:
 * Update Time:
 * Update Comments:
 */
class CurveDataListAdapter : BaseQuickAdapter<DetailedList, CurveDataListAdapter.VH>() {

    // 自定义ViewHolder类
    class VH(
        parent: ViewGroup,
        val binding: ItemCurveDataListBinding= ItemCurveDataListBinding.inflate(LayoutInflater.from(parent.context), parent, false),
    ) : RecyclerView.ViewHolder(binding.root)

    override fun onCreateViewHolder(context: Context, parent: ViewGroup, viewType: Int): VH {
        // 返回一个 ViewHolder
        return VH(parent)
    }

    override fun onBindViewHolder(holder: VH, position: Int, item: DetailedList?) {
        item?.run {
            holder.binding.dataBean = this
            holder.binding.tvXuhao.text = (position+1).toString()
            holder.binding.tvDate.text = time
            holder.binding.tvQiya.text = detailed[0].value
            if (detailed.size>1){
                holder.binding.lineWendu.visibility = View.VISIBLE
                holder.binding.tvWendu.visibility = View.VISIBLE
                holder.binding.tvWendu.text = detailed[1].value
            }else{
                holder.binding.lineWendu.visibility = View.GONE
                holder.binding.tvWendu.visibility = View.GONE
            }
        }
    }
}